import Vue from 'vue'
import ENUMS from './enums'

if (!Vue.prototype.$enum) {
  Object.defineProperties(Vue.prototype, {
    $enum: {
      get () {
        return ENUMS
      }
    }
  })
}

export const state = Vue.observable({
  // 商品类型 ID
  businessTypeId: '',
  // 下拉框选项
  options: {
    ticketChannel: [], // 需要声明，否则监听不生效
  },
  // 表单步骤
  steps: {
    1: [
      { title: '基本信息', active: 0, status: undefined, component: 'BasicInfomation' },
      { title: '商品详情', active: 1, status: undefined, component: 'CommodityDetail' },
      { title: '销售规则', active: 2, status: undefined, component: 'SaleRule' },
      { title: '检票设置', active: 3, status: undefined, component: 'CheckSettings' },
      { title: '分享设置', active: 4, status: undefined, component: 'ShareSettings' },
    ],
    3: [
      { title: '基本信息', active: 0, status: undefined, component: 'BasicInfomation' },
      { title: '商品详情', active: 1, status: undefined, component: 'CommodityDetail' },
      { title: '销售规则', active: 2, status: undefined, component: 'SaleRule' },
      { title: '分享设置', active: 3, status: undefined, component: 'ShareSettings' },
      { title: '限购设置', active: 4, status: undefined, component: 'PurchaseLimitationSettings' },
    ],
    4: [
      { title: '基本信息', active: 0, status: undefined, component: 'BasicInfomation' },
      { title: '酒店设施', active: 1, status: undefined, component: 'HotelFacilities' },
      { title: '房屋属性', active: 2, status: undefined, component: 'RoomAttributes' },
      { title: '商品详情', active: 3, status: undefined, component: 'CommodityDetail' },
      { title: '销售规则', active: 4, status: undefined, component: 'SaleRule' },
      { title: '分享设置', active: 5, status: undefined, component: 'ShareSettings' },
    ],
    5: [
      { title: '基本信息', active: 0, status: undefined, component: 'BasicInfomation' },
      { title: '商品详情', active: 1, status: undefined, component: 'CommodityDetail' },
      { title: '销售规则', active: 2, status: undefined, component: 'SaleRule' },
      { title: '分享设置', active: 3, status: undefined, component: 'ShareSettings' },
      { title: '限购设置', active: 4, status: undefined, component: 'PurchaseLimitationSettings' },
    ]
  }
})

export const mutations = {
  updateBusinessTypeId (payload) {
    state.businessTypeId = payload || ''
  },
  updateOptions (payload, which) {
    if (which) {
      state.options[which] = payload || []
    } else {
      state.options = payload || {}
    }
  },
  updateStepStatus (payload, step) {
    state.steps[state.businessTypeId][step].status = payload
  },
  resetStepStatus () {
    state.steps[state.businessTypeId].map(step => {
      step.status = undefined
    })
  }
}
